<?php
$currentDate = date_parse(date("Y-m-d"));
?>
<h3>Schedule History</h3>
<?php
$err = new ErrorCode();
$employeeSchedule = viewMySchedule(
        $_SESSION['userName'], $_SESSION['userPassHash']);
if ($employeeSchedule['0'] == $err::successRead) {

    $shiftsDuringCorrectTime = array();
    for ($i = 1; $i < count($employeeSchedule); $i++) {
        if (date_parse($employeeSchedule[$i]["date"]) < $currentDate) {
            $shiftsDuringCorrectTime[] = $employeeSchedule[$i];
        }
    }
    if (count($shiftsDuringCorrectTime) > 0) {
        ?>
        <table class="table-striped table">
            <thead>
                <tr>
                    <th>Role Name</th>
                    <th>Date</th>
                    <th>Start Time</th>
                    <th>End Time</th>
                </tr>
            </thead>
            <tbody>
                <?php
                for ($i = 0; $i < count($shiftsDuringCorrectTime); $i++) {
                    ?><tr>
                        <td><?php echo($shiftsDuringCorrectTime[$i]["roleName"]); ?></td>
                        <td><?php echo($shiftsDuringCorrectTime[$i]["date"]); ?></td>
                        <td><?php echo($shiftsDuringCorrectTime[$i]["startTime"]); ?></td>
                        <td><?php echo($shiftsDuringCorrectTime[$i]["endTime"]); ?></td>
                    </tr>
                    <?php
                }
                ?>
            </tbody>
        </table>
        <?php
    } else {
        //can display the error message here if needed 
        ?>No shifts were found.<?php
    }
} else {
    ?>Database Error. Maybe you don't have any shifts yet?<?php
}
?>